import random
import string

def generate_password(length=4):
    # 定义字符集，包括字母和数字
    characters = string.ascii_letters + string.digits
    # 从字符集中随机选择指定长度的字符
    password = ''.join(random.choice(characters) for i in range(length))
    return password

# 调用函数并打印结果
pwd = generate_password()
print(pwd)
